package com.xhtt.smart.card.common.enums;

import com.xhtt.smart.card.common.util.HexConver;

import java.util.Arrays;


/**
 * 功能码
 *
 * @author wangze
 * @date 2018-07-04 11:30.
 **/
public enum FunctionTypeEnum {


    GPS_UP(HexConver.int8ToByte(0x01), "室外定位数据上报"),
    INDOOR_GPS_UP(HexConver.int8ToByte(0x02), "室内定位数据上报"),
    ALERT_UP(HexConver.int8ToByte(0x03), "警报上报"),
    SENSOR_UP(HexConver.int8ToByte(0x04), "传感器信息上报"),
    LOGIN_UP(HexConver.int8ToByte(0x05), "登录平台"),
    HEART_UP(HexConver.int8ToByte(0x06), "发送心跳"),
    SET_GPS_DOWN(HexConver.int8ToByte(0x11), "设置室外定位方式"),
    SET_GATHER_TIME_DOWN(HexConver.int8ToByte(0x12), "设置采集的时间间隔"),
    SET_UPLOAD_INTERVAL_DOWN(HexConver.int8ToByte(0x13), "设置上报的时间间隔"),
    SET_GPS_OPEN_DOWN(HexConver.int8ToByte(0x14), "设置GNSS，蓝牙，定位模式开关"),
    ISSUE_ORDER_DOWN(HexConver.int8ToByte(0x15), "平台下发语音及震动、LED灯闪烁指令"),
    SYNCHRONOUS_TIME_DOWN(HexConver.int8ToByte(0x16), "同步终端时间"),
    INSTANT_DATA_DOWN(HexConver.int8ToByte(0x17), "设置存储在本地的定位数据立即上传(从后向前上传所有未上报信息）"),
    SET_UPLOAD_OPEN_DOWN(HexConver.int8ToByte(0x19), "开启或关闭定位数据上传功能"),
    RESET_DOWN(HexConver.int8ToByte(0x1B), "恢复工卡出厂设置"),
    TODO_DOWN(HexConver.int8ToByte(0x1C), "预留空中升级功能");


    private byte code;
    private String name;


    FunctionTypeEnum(byte code, String name) {

        this.code = code;
        this.name = name;
    }

    public byte getCode() {
        return code;
    }

    public void setCode(byte code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public static FunctionTypeEnum getEnumByCody(byte code) {
        return Arrays.stream(FunctionTypeEnum.values()).filter(x -> x.code == code).findFirst().orElse(null);

    }
}
